/**
 * 消灭星星小游戏
 * @author Thousand-paper-crane
 * @param {Number} min 
 * @param {Number} max
 * @returns undefined
 */
 function random(min,max){
    return Math.floor(Math.random()*(max-min+1)+min)
 } 
 var num=parseInt(document.querySelector('span').style.width)
 var a = setInterval(function(){
     num-=1
     document.querySelector('span').style.width=num
     if(num==0){
         alert('游戏结束')
         clearInterval(a)
         clearInterval(b)
     }
 },15)
 var b = setInterval(function(){
    var imgObj = document.createElement('img')
    imgObj.src='./star.gif'
    imgObj.style.width=random(20,100)
    imgObj.style.height=imgObj.style.width
    var maxLeft = (window.innerWidth || document.documentElement.clientWidth)-imgObj.width
    var maxTop = (window.innerHeight || document.documentElement.clientHeight)-imgObj.height
    imgObj.style.position='absolute'
    imgObj.style.left=random(0,maxLeft)+'px'
    imgObj.style.top=random(0,maxTop)+'px'
    document.body.appendChild(imgObj)
},500)
var sum =0
 document.body.onclick=function(evt){
     var e = evt || window.event
     var target = e.target || e.srcElement
     if(target.nodeName=='IMG'){
         document.body.removeChild(target)
         num+=50
         sum+=1
     }
     if(num>=550){
         alert('闯关成功')
         clearInterval(a)
         clearInterval(b)
     }
         document.querySelector('input').value='总共消灭星星：'+sum
 }
    